<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\BaseGoodsHy;

/**
 * BaseGoodsHySearch represents the model behind the search form about `app\models\BaseGoodsHy`.
 */
class BaseGoodsHySearch extends BaseGoodsHy
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['hy_id', 'sp_id', 'hysl', 'qdsl', 'status', 'statuses'], 'integer'],
            [['cpgn', 'gg', 'yxq', 'ccrq', 'fhdz', 'mjgsxx', 'lxr', 'dhhm', 'fbsj', 'spm'], 'safe'],
            [['sczdj', 'bhsdj', 'hsdj', 'zk'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = BaseGoodsHy::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'hy_id' => $this->hy_id,
            'sp_id' => $this->sp_id,
            'hysl' => $this->hysl,
            'qdsl' => $this->qdsl,
            'sczdj' => $this->sczdj,
            'bhsdj' => $this->bhsdj,
            'hsdj' => $this->hsdj,
            'zk' => $this->zk,
            'status' => $this->status,
            'statuses' => $this->statuses,
        ]);

        $query->andFilterWhere(['like', 'cpgn', $this->cpgn])
            ->andFilterWhere(['like', 'gg', $this->gg])
            ->andFilterWhere(['like', 'yxq', $this->yxq])
            ->andFilterWhere(['like', 'ccrq', $this->ccrq])
            ->andFilterWhere(['like', 'fhdz', $this->fhdz])
            ->andFilterWhere(['like', 'mjgsxx', $this->mjgsxx])
            ->andFilterWhere(['like', 'lxr', $this->lxr])
            ->andFilterWhere(['like', 'dhhm', $this->dhhm])
            ->andFilterWhere(['like', 'fbsj', $this->fbsj])
            ->andFilterWhere(['like', 'spm', $this->spm]);

        return $dataProvider;
    }
}
